﻿using System;
using RootMotion.FinalIK;
using UnityEngine;

namespace RootMotion.Demos
{
	// Token: 0x020000B3 RID: 179
	public abstract class PickUp2Handed : MonoBehaviour
	{
		// Token: 0x060005A2 RID: 1442 RVA: 0x00036770 File Offset: 0x00034970
		public void OnGUI()
		{
			GUILayout.BeginHorizontal(new GUILayoutOption[0]);
			GUILayout.Space((float)this.GUIspace);
			if (!this.holding)
			{
				if (GUILayout.Button("Pick Up " + this.obj.name, new GUILayoutOption[0]))
				{
					this.interactionSystem.StartInteraction(FullBodyBipedEffector.LeftHand, this.obj, false);
					this.interactionSystem.StartInteraction(FullBodyBipedEffector.RightHand, this.obj, false);
				}
			}
			else if (GUILayout.Button("Drop " + this.obj.name, new GUILayoutOption[0]))
			{
				this.interactionSystem.ResumeAll();
			}
			GUILayout.EndHorizontal();
		}

		// Token: 0x060005A3 RID: 1443
		public abstract void RotatePivot();

		// Token: 0x060005A4 RID: 1444 RVA: 0x00036828 File Offset: 0x00034A28
		public void Start()
		{
			InteractionSystem interactionSystem = this.interactionSystem;
			interactionSystem.OnInteractionStart = (InteractionSystem.InteractionDelegate)Delegate.Combine(interactionSystem.OnInteractionStart, new InteractionSystem.InteractionDelegate(this.OnStart));
			InteractionSystem interactionSystem2 = this.interactionSystem;
			interactionSystem2.OnInteractionPause = (InteractionSystem.InteractionDelegate)Delegate.Combine(interactionSystem2.OnInteractionPause, new InteractionSystem.InteractionDelegate(this.OnPause));
			InteractionSystem interactionSystem3 = this.interactionSystem;
			interactionSystem3.OnInteractionResume = (InteractionSystem.InteractionDelegate)Delegate.Combine(interactionSystem3.OnInteractionResume, new InteractionSystem.InteractionDelegate(this.OnDrop));
		}

		// Token: 0x060005A5 RID: 1445 RVA: 0x000368AC File Offset: 0x00034AAC
		public void OnPause(FullBodyBipedEffector effectorType, InteractionObject interactionObject)
		{
			if (effectorType != FullBodyBipedEffector.LeftHand)
			{
				return;
			}
			if (interactionObject != this.obj)
			{
				return;
			}
			this.obj.transform.parent = this.interactionSystem.transform;
			Rigidbody component = this.obj.GetComponent<Rigidbody>();
			if (component != null)
			{
				component.isKinematic = true;
			}
			this.pickUpPosition = this.obj.transform.position;
			this.pickUpRotation = this.obj.transform.rotation;
			this.holdWeight = 0f;
			this.holdWeightVel = 0f;
		}

		// Token: 0x060005A6 RID: 1446 RVA: 0x000059E6 File Offset: 0x00003BE6
		public void OnStart(FullBodyBipedEffector effectorType, InteractionObject interactionObject)
		{
			if (effectorType != FullBodyBipedEffector.LeftHand)
			{
				return;
			}
			if (interactionObject != this.obj)
			{
				return;
			}
			this.RotatePivot();
			this.holdPoint.rotation = this.obj.transform.rotation;
		}

		// Token: 0x060005A7 RID: 1447 RVA: 0x00036950 File Offset: 0x00034B50
		public void OnDrop(FullBodyBipedEffector effectorType, InteractionObject interactionObject)
		{
			if (effectorType != FullBodyBipedEffector.LeftHand)
			{
				return;
			}
			if (interactionObject != this.obj)
			{
				return;
			}
			this.obj.transform.parent = null;
			if (this.obj.GetComponent<Rigidbody>() != null)
			{
				this.obj.GetComponent<Rigidbody>().isKinematic = false;
			}
		}

		// Token: 0x060005A8 RID: 1448 RVA: 0x000369B0 File Offset: 0x00034BB0
		public void LateUpdate()
		{
			if (this.holding)
			{
				this.holdWeight = Mathf.SmoothDamp(this.holdWeight, 1f, ref this.holdWeightVel, this.pickUpTime);
				this.obj.transform.position = Vector3.Lerp(this.pickUpPosition, this.holdPoint.position, this.holdWeight);
				this.obj.transform.rotation = Quaternion.Lerp(this.pickUpRotation, this.holdPoint.rotation, this.holdWeight);
			}
		}

		// Token: 0x17000080 RID: 128
		// (get) Token: 0x060005A9 RID: 1449 RVA: 0x00005A23 File Offset: 0x00003C23
		public bool holding
		{
			get
			{
				return this.interactionSystem.IsPaused(FullBodyBipedEffector.LeftHand);
			}
		}

		// Token: 0x060005AA RID: 1450 RVA: 0x00036A44 File Offset: 0x00034C44
		public void OnDestroy()
		{
			if (this.interactionSystem == null)
			{
				return;
			}
			InteractionSystem interactionSystem = this.interactionSystem;
			interactionSystem.OnInteractionStart = (InteractionSystem.InteractionDelegate)Delegate.Remove(interactionSystem.OnInteractionStart, new InteractionSystem.InteractionDelegate(this.OnStart));
			InteractionSystem interactionSystem2 = this.interactionSystem;
			interactionSystem2.OnInteractionPause = (InteractionSystem.InteractionDelegate)Delegate.Remove(interactionSystem2.OnInteractionPause, new InteractionSystem.InteractionDelegate(this.OnPause));
			InteractionSystem interactionSystem3 = this.interactionSystem;
			interactionSystem3.OnInteractionResume = (InteractionSystem.InteractionDelegate)Delegate.Remove(interactionSystem3.OnInteractionResume, new InteractionSystem.InteractionDelegate(this.OnDrop));
		}

		// Token: 0x040004B5 RID: 1205
		[SerializeField]
		public int GUIspace;

		// Token: 0x040004B6 RID: 1206
		public InteractionSystem interactionSystem;

		// Token: 0x040004B7 RID: 1207
		public InteractionObject obj;

		// Token: 0x040004B8 RID: 1208
		public Transform pivot;

		// Token: 0x040004B9 RID: 1209
		public Transform holdPoint;

		// Token: 0x040004BA RID: 1210
		public float pickUpTime = 0.3f;

		// Token: 0x040004BB RID: 1211
		public float holdWeight;

		// Token: 0x040004BC RID: 1212
		public float holdWeightVel;

		// Token: 0x040004BD RID: 1213
		public Vector3 pickUpPosition;

		// Token: 0x040004BE RID: 1214
		public Quaternion pickUpRotation;
	}
}
